package com.erp.service.util.net;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import java.util.ArrayList;
import java.util.List;

/**
 * HTTP参数
 * @author ccl
 *
 */
public class HttpParams {
	
	private List<NameValuePair> nameValuePairList=new ArrayList<NameValuePair>();
	/**
	 * 构造函数
	 */
	public HttpParams(){
	}
	
	/**
	 * http参数构造函数
	 * @param name 参数键值KEY
	 * @param value 参数值
	 */
	public HttpParams(String name,String value){
		this.add(name, value);
	}
	
	/**
	 * 通过键值对LIST构造HTTP参数
	 * @param nameValuePairList 键值对LIST
	 */
	public HttpParams(List<NameValuePair> nameValuePairList){
		this.addAll(nameValuePairList);
	}
	
	/**
	 * 添加参数
	 * @param name 键值KEY
	 * @param value 值
	 * @return 已添加参数的HttpParams
	 */
	public HttpParams add(String name,String value){
		nameValuePairList.add(new BasicNameValuePair(name, value));
		return this;
	}
	/**
	 * 通过键值对LIST添加参数
	 * @param nameValuePairList 键值对LIST
	 */
	public HttpParams addAll(List<NameValuePair> nameValuePairList){
		this.nameValuePairList.addAll(nameValuePairList);
		return this;
	}
	
	/**
	 * 获取键值对List
	 * @return 键值对List
	 */
	public List<NameValuePair> toNameValuePairs(){
		return nameValuePairList;
	}
}
